<?php
/**
 * 系统消息业务层
 * Create by PhpStorm
 * User: lijia
 * Data: 2020/8/7
 * Time: 14:13
 */

namespace app\admin\business;

use app\admin\model\Feedback;
use app\admin\model\Message;
use think\facade\Db;

class MessageBus
{
    public $model;
    public function __construct()
    {
        $this->model = new Message();
    }

    public function getList($where,$sort_by,$sort_order,$pageSize,$page){
        $list = Db::name('message')->alias('a')
            ->where($where)
            ->order($sort_by . ' ' . $sort_order)
            ->field('a.*')
            ->paginate(array('list_rows' => $pageSize, 'page' => $page))
            ->toArray();
        foreach ($list['data'] as $k => $v){
            $list['data'][$k]['content'] = trimHtml($v['content'],0,30,true);
        }
        return $list;
    }

    public function getInfo($id){
        return $this->model->where('id',$id)->find();
    }

    public function edit($where,$data){
        return $this->model->where($where)->update($data);
    }

    public function add($data){
        return $this->model->save($data);
    }

    public function del($id){
        return $this->model->where(['id'=>$id])->delete();
    }

    public function doStatus($id,$status){
        return $this->model->status($id,$status);
    }
}